package com.dc.free.interceptor;

import com.dc.free.controller.BaseController;
import com.dc.free.db.model.CAction;
import com.dc.free.db.service.CAtionService;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.kit.StrKit;

public class ActionInterceptor implements Interceptor {
	
	@Override
	public void intercept(Invocation inv) {
		BaseController baseController = (BaseController) inv.getController();
		String actionId = baseController.getPara("action_id");
		
		//添加活动id
		if(StrKit.isBlank(actionId)) {
			CAction action = CAtionService.getFirstActivatedAction();
			
			if(action == null) {
				baseController.renderHtml("没有活动，敬请期待...");
				return;
			}
			actionId = action.getId();
		}
		
		baseController.addData("actionId", actionId);
		inv.invoke();
	}

}
